<template>
	<view class="main">
		<uni-nav-bar :fixed="true" left-icon="back" @click-left="back" @click-right="clickright()" :right-text="caozuo == 1 ? '操作' : '完成'" title="我的收藏"></uni-nav-bar>
		<view :class="caozuo == 1 ? 'list' : 'list active'" v-for="(item, index) in list" :key="index">
			<view class="yuan" @tap="select(index)">
				<image v-if="item.seleted == 0" src="../../../static/yuan.png" mode="widthFix"></image>
				<image v-else src="../../../static/yuan_s.png" mode="widthFix"></image>
			</view>
			<view class="pannel" @tap="goDetail(item.id, item.type)">
				<view class="left"><image :src="item.thumb" mode="widthFix"></image></view>
				<view class="right">
					<view class="title">{{ item.name }}</view>
					<view class="bottom">
						<text class="money">{{ item.price }}万</text>
					</view>
				</view>
			</view>
		</view>
		<view class="footer" v-if="caozuo == 2">
			<view class="selected_all" @tap="selet_all()">
				<view class="yuan">
					<image v-if="selected_all == 0" src="../../../static/yuan.png" mode="widthFix"></image>
					<image v-else src="../../../static/yuan_s.png" mode="widthFix"></image>
				</view>
				<text>全选</text>
			</view>
			<view class="delete" @tap="del()">删除</view>
		</view>
	</view>
</template>

<script>
import uniNavBar from '@/components/uni-nav-bar/uni-nav-bar.vue';
import uniIcons from '@/components/uni-icons/uni-icons.vue';
export default {
	components: { uniNavBar, uniIcons },
	data() {
		return {
			list: [],
			caozuo: 1
		};
	},
	computed: {
		selected_all() {
			if (this.list.length <= 0) {
				return 0;
			}
			let selected_all = 1;
			const list = this.list;
			for (let key in list) {
				if (list[key]['seleted'] == 0) {
					selected_all = 0;
				}
			}
			return selected_all;
		}
	},
	onLoad() {
		this.getData();
	},
	methods: {
		async getData() {
			let res = await this.$request.post('/landed/getCollectionList', {});
			let list = res.data.data.list || [];
			for (let key in list) {
				list[key]['seleted'] = 0;
			}
			this.list = list;
		},
		goDetail(id, type) {
			if (type == 3) {
				uni.navigateTo({
					url: '/pages/house_property/rentingdetail/rentingdetail?id=' + id
				});
			} else if (type == 2) {
				uni.navigateTo({
					url: '/pages/house_property/seconddetail/seconddetail?id=' + id
				});
			} else if (type == 1) {
				uni.navigateTo({
					url: '/pages/house_property/propertiesdetail/propertiesdetail?id=' + id
				});
			}
		},
		clickright() {
			if (this.caozuo == 1) {
				this.caozuo = 2;
			} else {
				this.caozuo = 1;
			}
		},
		select(index) {
			let list = this.list;
			list[index]['seleted'] = list[index]['seleted'] == 0 ? 1 : 0;
			this.list = list;
		},
		selet_all() {
			let list = this.list;
			let seleted = this.selected_all == 0 ? 1 : 0;
			for (let key in list) {
				list[key]['seleted'] = seleted;
			}
			this.list = list;
		},
		async del() {
			let ids = [];
			let list = this.list;
			for (let key in list) {
				if (list[key]['seleted'] == 1) {
					ids.push(list[key]['collection_id']);
				}
			}
			let res = await this.$request.post('/landed/delCollection', {data:{ids:ids.join(',')}});
			this.getData();
		},
		back() {
			uni.navigateBack({
				delta: 1
			});
		}
	}
};
</script>

<style lang="scss">
page {
	background-color: #f3f3f3;
}

.main {
	padding-bottom: 100upx;
}
.list {
	width: 100%;
	box-sizing: border-box;
	position: relative;
	padding-left: 30upx;
	padding-right: 30upx;
	height: 220upx;
	margin-top: 30upx;
	&.active {
		padding-left: 80upx;
		.yuan {
			display: block;
		}
	}
	.yuan {
		display: none;
		width: 60upx;
		height: 60upx;
		position: absolute;
		top: 50%;
		left: 10upx;
		transform: translateY(-50%);
		image {
			width: 100%;
		}
	}
	.pannel {
		width: 100%;
		height: 220upx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: flex-start;
		position: relative;
		background-color: #ffffff;
		border-radius: 20upx;
		overflow: hidden;
		.left {
			width: 230upx;
			height: 220upx;
			overflow: hidden;
			image {
				height: 100%;
			}
		}
		.right {
			width: calc(100% - 320upx);
			height: 100%;
			display: flex;
			flex-direction: column;
			align-items: flex-start;
			justify-content: space-between;
			box-sizing: border-box;
			padding: 20upx;
			line-height: 1.5em;
			font-size: $uni-font-size-base;
			color: $uni-color-subtitle;
			.title {
				font-size: $uni-font-size-lg;
				color: $uni-color-title;
				line-height: 1.5em;
				color: #333333;
			}
			.bottom {
				color: #f73366;
				font-size: $uni-font-size-lg;
				font-weight: 700;
			}
		}
	}
}
.footer {
	width: 100%;
	height: 100upx;
	display: flex;
	align-items: center;
	justify-content: space-between;
	background-color: #ffffff;
	position: fixed;
	bottom: 0;
	left: 0;
	box-sizing: border-box;
	padding: 0 20upx;
	.selected_all {
		width: 140upx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: $uni-font-size-base;
		color: #333;
		.yuan {
			width: 60upx;
			height: 60upx;
			image {
				width: 100%;
			}
		}
	}
	.delete {
		width: 150upx;
		height: 70upx;
		line-height: 70upx;
		text-align: center;
		box-sizing: border-box;
		border-radius: 70upx;
		font-size: $uni-font-size-base;
		border: 2upx solid #c6c6c6;
		color: #c6c6c6;
	}
}
</style>
